#!/usr/bin/python
# encoding: utf-8;
# from importlib.resources import path
import os
import os.path
from stat import *
import sys

sys.path.append("../../..")
from s2c.tools.dict import service_app
from s2c.tools.utils import read_file, write_file, run_cmd, run_cmdb
from s2c.rules.conf import DOCKER_PATH_TMP

# =============nginx相关依赖文件配置==========start===========================
# Nginx 默认的config文件
nginx_cfg = '/etc/nginx/nginx.conf'
# Nginx 需要匹配的规则,注意，如果关键字中有相互包含，需要把唯一的关键字放在前面，如：'ssl_certificate_key', 'ssl_certificate'
nginx_keyword = ['ssl_certificate_key', 'ssl_certificate', 'root', 'access_log', 'error_log', 'include']


# Nginx 需要手动copy的文件
# nginx_default_file = ['/var/lib/nginx','/usr/lib64/perl5','/usr/share/perl5','/usr/lib64/libgd.so.3','/usr/lib64/libfontconfig.so.1','/usr/lib64/libfreetype.so.6','/usr/lib64/libX11.so.6','/usr/lib64/libxcb.so.1','/usr/lib64/libXau.so.6','/usr/lib64/libxslt.so.1','/usr/lib64/libexslt.so.0']
# =============nginx相关依赖文件配置==========end===========================

# 启动配置设置
def httpd_boot():
    # 先产生httpd-foreground文件
    cmd_str = '#!/bin/bash\n'
    cmd_str += 'set -e\n\n'
    cmd_str += '# Apache gets grumpy about PID files pre-existing\n'
    cmd_str += 'rm -f /usr/local/apache2/logs/httpd.pid\n\n'
    cmd_str += 'exec httpd -DFOREGROUND\n'
    file_path = DOCKER_PATH_TMP + 'httpd-foreground'
    write_file(file_path, cmd_str)
    run_cmd('chmod +x ' + file_path)
    del_file = '\\rm ' + DOCKER_PATH_TMP + 'run/httpd/cgisock.*'
    print('del tmp file', del_file)
    run_cmdb(del_file)
    tmp = DOCKER_PATH_TMP + 'run/php-fpm/www.sock'
    if os.path.exists(tmp):
        run_cmdb('\\rm ' + tmp)

    return 'CMD ["httpd-foreground"]\n\n#docker build -t myhttpdtest:00 .\n#docker run 指令 docker run -itd -p 8082:80 --name openeuler-new --privileged=true autobuildphp-fpm:00 /sbin/init\n\n'


#  man 方法
def main():
    print("Hello, httpd!")
    # tmp = nginx_config_dir()
    ret = os.path.isdir('D:\\Work\\2022\\iot\\20220816\\main.c')
    print('=======', ret)


if __name__ == "__main__":
    main()
